import { RosterInterface } from '@/api/interface/personnel/roster/roster';
import { BasicForm } from '@/components/ProForm/interface';
import { PublicInterface } from '@/interface/public';

/**
 * 家庭信息
 */

export function useFamilyInfoForm(proTableBox: PublicInterface.ProTableValue) {
  let familyInfoForm = reactive<BasicForm<RosterInterface.ReqFamilyInfoSave>>({
    form: {
      id: null,
      age: null,
      company: '',
      job: '',
      phone: '',
      name: '',
      relation: '',
      rosterId: null,
      remark: ''
    },
    title: '',
    minWidth: 660,
    labelWidth: [100, 120],
    visible: false,
    formAttrs: {
      labelWidth: '120px'
    },
    transitionArr: [
      {
        oldField: 'relation',
        newField: 'relation'
      }
    ],
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'input',
        label: '主表id',
        prop: 'rosterId',
        hide: true
      },
      {
        type: 'input',
        hide: false,
        prop: 'name',
        label: '姓名',
        rules: [
          {
            required: true,
            message: '姓名',
            trigger: 'change'
          }
        ]
      },

      {
        type: 'select',
        hide: false,
        prop: 'relation',
        label: '关系',
        rules: [
          {
            required: true,
            message: '关系',
            trigger: 'blur'
          }
        ],
        children: []
      },
      {
        type: 'input',
        hide: false,
        prop: 'age',
        label: '年龄',
        rules: [
          {
            required: true,
            message: '年龄',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'job',
        label: '职业',

        rules: [
          {
            required: true,
            message: '职业',
            trigger: 'blur'
          }
        ]
      },

      {
        type: 'input',
        hide: false,
        prop: 'company',
        label: '单位或住址',
        rules: [
          {
            required: true,
            message: '单位或住址',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'phone',
        label: '联系电话',
        rules: [
          {
            required: true,
            message: '联系电话',
            trigger: 'blur'
          }
        ]
      },
      {
        type: 'input',
        hide: false,
        prop: 'remark',
        label: 'remark',
        attrs: {
          style: {
            width: '500px'
          }
        }
      }
    ]
  });

  /**
   * @description: 保存表单数据
   * @return {*}
   */
  const saveAddFamilyInfoForm = async form => {
    await familyInfoSave(form);
    familyInfoForm.visible = false;
    elMessage();
    proTableBox.value?.getTableList();
  };

  return { familyInfoForm, saveAddFamilyInfoForm };
}
